#--------------------------------------
# Test a multiply routine
#--------------------------------------
	org		0x0000
	ori		$15, $zero, 0x800
	nop
	nop
	nop
	nop
mult:
	nop
	nop
	nop
	nop
	sw		$zero, 8($15)     # clear result
	nop
	nop
	nop
	nop
	ori		$1, $zero, 0x01
	nop
	nop
	nop
	nop
	ori		$2, $zero, 0x02
	nop
	nop
	nop
	nop
	lw		$5, 0($15)
	nop
	nop
	nop
	nop
	lw		$6, 4($15)
	nop
	nop
	nop
	nop
	or		$7, $zero, $zero
	nop
	nop
	nop
	nop
	or		$8, $zero, $zero
	nop
	nop
	nop
	nop


# one operand in $5, one in $6
# shift the one in $5 right
# shift the one in $6 left

multloop:
	nop
	nop
	nop
	nop
	and		$7, $5, $1
	nop
	nop
	nop
	nop
	beq		$zero, $7, multnoadd
	nop
	nop
	nop
	nop
	addu	$8, $8, $6
	nop
	nop
	nop
	nop

multnoadd:
	nop
	nop
	nop
	nop
	sll		$6, $6, 1
	nop
	nop
	nop
	nop
	srl		$5, $5, 1
	nop
	nop
	nop
	nop
	beq		$zero, $5, multend
	nop
	nop
	nop
	nop
	beq		$zero, $zero, multloop
	nop
	nop
	nop
	nop
multend:
	nop
	nop
	nop
	nop
	sw		$8, 8($15) # answer 32 should be at address 88
	nop
	nop
	nop
	nop
	halt 
        	
	org 	0x800
	cfw		5
	cfw 	10 

